<template>
  <div class="rootBody">
    <div class="body">
      <div class="top">
        <div class="top1"><img src="../../images/login/top1.jpg"/></div>
        <div class="top2">
          <div class="top2_1"><img src="../../images/login/top1_1.jpg"></div>
          <div class="top2_2"><img src="../../images/login/top2.jpg"/></div>
        </div>
      </div>

      <form name="form1" id="form1">
        <div class="zhong">
          <div class="zhong1"><img src="../../images/login/zhongzuo.jpg"></div>
          <div class="zhong2">
            <table width="275" border="0" cellpadding="0" cellspacing="0" class="zhong2_1">
              <tr>
                <td width="64" align="right" style="padding:5px;"><img src="../../images/login/yonghuming.jpg"/></td>
                <td width="211" style="padding:5px;">
                  <input name="user" v-model="formModel.userName" placeholder="用户名" type="text" style="width:170px; height:18px;">
                </td>
              </tr>
              <tr>
                <td align="right" style="padding:5px;">
                  <img src="../../images/login/mima.jpg"/>
                </td>
                <td style="padding:5px;">
                  <input id="password" v-model="formModel.userPwd" placeholder="密码" name="password" type="password" style="width:170px; height:18px;">
                </td>
              </tr>
            </table>
          </div>
          <div class="zhong3">
            <input name="" id='denglu' type="button" @click="loginCheck"></div>
        </div>
      </form>

      <div class="bottom">后台技术支持：<a href="http://www.zjteam.com" target="_blank">帷拓科技</a></div>
    </div>
  </div>
</template>

<script>
    import Cookies from 'js-cookie';
    import {mapMutations} from "vuex";
    export default {
        name: "index",
        data(){
            return {
                formModel:{
                    userName:'',
                    userPwd:'',
                },
                formRules:{
                    userName: [
                        { required: true, message: '请输入用户名', trigger: 'blur' },
                    ],
                    userPwd: [
                        { required: true, message: '请输入密码', trigger: 'blur' },
                    ]
                },
            }
        },
        methods:{
            loginCheck(){
              // console.log(this.formModel);
                if(this.formModel.userName==""){
                    this.$Message.warning("请输入用户名")
                }else if(this.formModel.userPwd==""){
                    this.$Message.warning("请输入密码")
                }else{
                    this.login();
                }
            },
            login(){
                let that=this;
                this.$app.post('/tadmin/login', {
                    userName:that.formModel.userName,
                    userPwd:that.formModel.userPwd,
                }).then((res)=>{

                    var millisecond = new Date().getTime();
                    var expiresTime = new Date(millisecond + 60 * 1000 * 60);

                    if(res.data.code==0){
                      // that.$store.dispatch("getUserModules", { vm: this });



                      that.$app.setHeader(res.data.data.auth_code);
                      Cookies.set("userName",that.formModel.userName,{expires:expiresTime});
                      Cookies.set("userNick",res.data.data.userNick,{expires:expiresTime});
                      that.$Message.success("登录成功")
                      that.$router.push({
                          name:"home"
                      });

                      that.$store.dispatch("getUserModules",{vm:this});
                      // that.getUserModules({ vm: this });
                    }else{
                        that.$Message.error("登录失败")
                    }
                })
            }
        }
    }
</script>

<style lang="less" scoped>
  @import "css/css.css";


  .register{
    &:hover{
      cursor: pointer;
      color: blue;
    }
  }
</style>
